package com.th.supcom.pds.phamapply.client.widget.checkdispense;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.th.supcom.pds.phamapply.client.model.InpPhamDispenseDetailModel;
import com.th.supcom.pds.phamapply.client.widget.phamdispense.PhamDispenseFields;

/**
 * 核对发药事件监听
 * 
 * @author 杨冲
 */
public class InpCheckDispenseListener
{
    private InpCheckDispenseButtons m_inpCheckDispenseButtons;
    private InpCheckDispenseAction m_inpCheckDispenseAction;
    private PhamDispenseFields m_phamDispenseFields;
    private InpCheckDispenseNurseUnitInfoGrid m_checkDispenseNurseUnitInfoGrid;

    /**
     * 设置核对发药按钮组件
     * 
     * @param phamDispenseButtons
     */
    public void setInpCheckDispenseButtons (InpCheckDispenseButtons inpCheckDispenseButtons)
    {

        this.m_inpCheckDispenseButtons = inpCheckDispenseButtons;
    }

    /**
     * 设置核对发药事件
     * 
     * @param phamDispenseAction
     */
    public void setInpCheckDispenseAction (InpCheckDispenseAction inpCheckDispenseAction)
    {

        this.m_inpCheckDispenseAction = inpCheckDispenseAction;
    }

    /**
     * 设置核对发药文本组件
     * 
     * @param phamapplyFields
     */
    public void setPhamDispenseFields (PhamDispenseFields phamDispenseFields)
    {

        this.m_phamDispenseFields = phamDispenseFields;
    }

    /**
     * 设置核对发药护理单元Grid
     * 
     * @param checkDispenseNurseUnitInfoGrid
     */
    public void setCheckDispenseNurseUnitInfoGrid (InpCheckDispenseNurseUnitInfoGrid checkDispenseNurseUnitInfoGrid)
    {

        m_checkDispenseNurseUnitInfoGrid = checkDispenseNurseUnitInfoGrid;
    }

    /**
     * 初始化所有的Listener
     */
    public void initListeners ()
    {
        addPhamDispenseListener ();
        addQueryDispenseListener ();
    }

    /**
     * 设置发药事件监听
     */
    public void addPhamDispenseListener ()
    {
        m_inpCheckDispenseButtons.getDispenseButton ().addSelectionListener (new SelectionListener <ButtonEvent> ()
        {

            @Override
            public void componentSelected (ButtonEvent ce)
            {
                openOperateRecordWindow ();
            }
        });
        m_inpCheckDispenseButtons.getDetailClearBtn ().addSelectionListener (new SelectionListener <ButtonEvent> ()
        {

            @Override
            public void componentSelected (ButtonEvent ce)
            {
                m_inpCheckDispenseAction.clear ();
            }

        });

    }

    /**
     * 打开员工操作记录窗口
     */
    public void openOperateRecordWindow ()
    {
        InpCheckDispenseOperateRecordWindow window = new InpCheckDispenseOperateRecordWindow ();
        window.setInpCheckDispenseButtons (m_inpCheckDispenseButtons);
        window.setPhamDispenseFields (m_phamDispenseFields);
        window.setDispenseAction (m_inpCheckDispenseAction);
        window.initUI ();
        window.show ();
    }

    /**
     * 设置查询摆药明细事件
     */
    public void addQueryDispenseListener ()
    {
        m_checkDispenseNurseUnitInfoGrid.getGrid ().addListener (Events.CellClick, new Listener <GridEvent <InpPhamDispenseDetailModel>> ()
        {
            @Override
            public void handleEvent (GridEvent <InpPhamDispenseDetailModel> be)
            {
                m_inpCheckDispenseAction.getDispenseDetailByGrid ();
            }
        });
    }
}
